package com.atguigu.serviceedu.controller;


import com.aiguigu.common_utils.R;
import com.atguigu.serviceedu.entity.EduChapter;
import com.atguigu.serviceedu.entity.EduVideo;
import com.atguigu.serviceedu.entity.chapter.ChapterVo;
import com.atguigu.serviceedu.service.EduChapterService;
import com.atguigu.serviceedu.service.EduVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author zzc
 * @since 2022-09-16
 */
@RestController
@RequestMapping("/serviceedu/video")
//@CrossOrigin
public class EduVideoController {
    @Autowired
    private EduVideoService videoService;

    @PostMapping("addVideo")
    public R addVideo(@RequestBody EduVideo eduVideo){
        videoService.save(eduVideo);
        return R.ok();
    }
    @GetMapping("getVideoInfo/{Id}")
    public R getVideoById(@PathVariable String Id){
        EduVideo eduVideo = videoService.getById(Id);
        return R.ok().data("video",eduVideo);
    }
    @PostMapping("updateVideo")
    public R updateVideo(@RequestBody EduVideo eduVideo){
        videoService.updateById(eduVideo);
        return R.ok();
    }
    @DeleteMapping("{Id}")
    public R deleteVideo(@PathVariable String Id){
        boolean result = videoService.removeVideoById(Id);
        if(result){
            return R.ok();
        }else{
            return R.error().message("删除失败");
        }
    }
}

